(function($, window, document, undefined) {
  
  $(document).on('click', '.promotion-tab-item', function(e) {
    e.preventDefault()

    var $el = $(e.target)

    if (!$el.is('.promotion-tab-item')) {
      $el = $el.parents('.promotion-tab-item')
    }

    var index = $el.index()

    $el
      .addClass('active')
      .siblings()
      .removeClass('active')

    $('.promotion-panel-item')
      .eq(index)
      .addClass('active')
      .siblings()
      .removeClass('active')

  })

  // 查看详情
  $(document).on('click', '.promotion-list-item-view', function(e) {

    var $el = $(e.target)

    if (!$el.is('.promotion-list-item-view')) {
      $el = $el.parents('.promotion-list-item-view')
    }

    var href = $el.attr('href')

    // 如果有链接则直接打开链接
    if (href && href !== '#') {
      return
    }

    e.preventDefault()
    
    var src = $el.data('news')

    if (!src) {
      return
    }
    
    var title = $el.parents('.promotion-list-item').find('.promotion-list-item-title').text()

    //iframe窗
    // layer.open({
    //   type: 2,
    //   shade: .5,
    //   title: title,
    //   shadeClose: true,
    //   maxmin: true, //开启最大化最小化按钮
    //   area: ['893px', '600px'],
    //   content: src
    // });
    
    $('#promotion-modal').modal()

  })

})(jQuery, window, document)